home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / ldir.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  6KB  |  243 lines

  1. program ldir;
  2.  
  3. { Testprogram for the nwFile unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  4.  
  5. { LDIR is an alternative for NDIR, showing the use of the
  6.   ScanDirectoryEntry function. }
  7.  
  8. uses nwMisc,nwBindry,nwFile;
  9.  
  10. Function GetEntryAttributeString(Attr:Longint):string;
  11. Var res:string;
  12. begin
  13. if (Attr and A_DIRECTORY)=0
  14.  then res:=' RwSAXHSyTPCDR '
  15.  else res:=' -----HSy-P-DR ';
  16. if (Attr and A_HIDDEN)=0 then res[7]:='-';
  17. if (Attr and A_SYSTEM)=0 then begin res[8]:='-';res[9]:='-'; end;
  18. if (Attr and A_RENAME_INHIBIT)=0 then res[14]:='-';
  19. if (Attr and A_DELETE_INHIBIT)=0 then res[13]:='-';
  20. if (Attr and A_PURGE)=0 then res[11]:='-';
  21. if (Attr and A_DIRECTORY)=0
  22.  then begin
  23.       if ((Attr and A_READ_ONLY)>0) then res[3]:='o';
  24.       if (Attr and A_EXECUTE_ONLY)=0 then res[6]:='-';
  25.       if (Attr and A_NEEDS_ARCHIVED)=0 then res[5]:='-';
  26.       if (Attr and A_SHAREABLE)=0 then res[4]:='-';
  27.       if (Attr and A_TRANSACTIONAL)=0 then res[10]:='-';
  28.       if (Attr and A_COPY_INHIBIT)=0 then res[12]:='-';
  29.       end;
  30. GetEntryAttributeString:=res;
  31. end;
  32.  
  33. Var DirHandle:Byte;
  34.     DirPath:String;
  35.     SequenceNumber:Byte;
  36.     TrusteeInfo: TtrusteeInformation;
  37.  
  38.     t:Byte;
  39.     ObjName:string;
  40.     ObjType:word;
  41.     ObjId:Longint;
  42.     DH,EffRights:byte;
  43.  
  44.     EntryName:string;
  45.     SearchFlags:Longint;
  46.     EntryId:Longint;
  47.     Entry:Tentry;
  48.     s,s1:string;
  49.  
  50.     p:byte;
  51.     OwnerName:string;
  52.     OwnerType:word;
  53.  
  54.     entry2:Tentry;
  55. begin
  56.  
  57. DirHandle:=0;
  58.  
  59. if ParamCount>0
  60.  then s:=paramStr(1)
  61.  else s:='.';
  62.  
  63. IF NOT GetTrueEntryName(s,DirPath)
  64.  then begin
  65.       writeln('Error resolving given filename (err: 0-',nwfile.result,')');
  66.       halt(1);
  67.       end;
  68.  
  69. if pos(':',DirPath)=2
  70.  then begin
  71.       writeln('You cannot use this program on a local drive.');
  72.       halt(1);
  73.       end;
  74.  
  75. { ok. Try to separate EntryName from path }
  76.  
  77. p:=ord(DirPath[0]);
  78. while (p>0) and (DirPath[p]<>'\') do dec(p);
  79.  
  80. s:=copy(DirPath,p+1,255);
  81. if (pos('.',s)>0) or (pos('*',s)>0) or (pos('?',s)>0)
  82.  then begin { last part is definately a filename }
  83.       EntryName:=s;
  84.       DirPath[0]:=chr(p-1);
  85.       IF NOT AllocTemporaryDirHandle(31,0,DirPath,DH,EffRights)
  86.        then begin
  87.             writeln('Could not locate directory (err: 1-',nwfile.result,')');
  88.             halt(1);
  89.             end;
  90.       end
  91.  else begin
  92.       IF AllocTemporaryDirHandle(31,0,DirPath,DH,EffRights) { assume it's a path}
  93.        then begin
  94.             { whole thing appears to be a path.. }
  95.             EntryName:='*';
  96.             end
  97.        else begin
  98.             { whoops.. not a path, but a filename without an extension }
  99.             EntryName:=s;
  100.             DirPath[0]:=chr(p-1);
  101.             IF NOT AllocTemporaryDirHandle(31,0,DirPath,DH,EffRights)
  102.              then begin
  103.                   writeln('Could not locate directory (err: 2-',nwfile.result,')');
  104.                   halt(1);
  105.                   end;
  106.             end;
  107.       end;
  108.  
  109.  
  110. writeln('EntryName         Size Flags           EntryID  Creation        Owner');
  111. writeln('------------+---------+---------------+--------+---------------+----------');
  112.  
  113. SearchFlags:=$ef; { all NON directories, i.e. all files }
  114. EntryId:=-1;
  115.  
  116. While ScanDirectoryEntry(DH,EntryName,SearchFlags,EntryID,Entry)
  117.  do begin
  118.   s:=entry.EntryName;
  119.     p:=pos('.',s);
  120.     if p=0
  121.      then begin
  122.           s:=s+'               ';
  123.           s[0]:=#12;
  124.           end
  125.      else begin
  126.           s1:=copy(s,1,p-1)+'           ';
  127.           s1[0]:=#8;
  128.           s:=s1+copy(s,p,255)+'  ';
  129.           s[0]:=#12;
  130.           end;
  131.     write(s);
  132.     write(entry.FileSize:10);
  133.     s:=GetEntryAttributeString(entry.Attributes);
  134.     write(' F',s);
  135.     write(HexStr(entryId,8));
  136.  
  137.     NovTime2String(entry.CreationTime,s);
  138.     delete(s,1,5);dec(s[0],3);
  139.     delete(s,8,2);
  140.     s[3]:='-';s[7]:='-';
  141.     write(' ',s);
  142.  
  143.     GetBinderyObjectName(entry.OwnerId,OwnerName,OwnerType);
  144.     s:=ownerName+'         ';
  145.     s[0]:=#10; write(' ',s);
  146.     writeln;
  147.  
  148.     end;
  149.  
  150. if nwFile.result<>$FF { no more matching entries }
  151.  then writeln('Error scanning directory information (err : 3-',nwfile.result,')');
  152.  
  153.  
  154. {-- As an extra gimmick: if you DEFINE ShowScan, salvagable files will
  155.  also be shown.. }
  156.  
  157. {$IFDEF ShowScan}
  158.  
  159. { Scan salvagable files.. }
  160. EntryId:=-1;
  161.  
  162. WHILE ScanSalvagableFiles(DH,EntryId,Entry)
  163.  do begin
  164.     s:=entry.EntryName;
  165.     p:=pos('.',s);
  166.     if p=0
  167.      then begin
  168.           s:=s+'               ';
  169.           s[0]:=#12;
  170.           end
  171.      else begin
  172.           s1:=copy(s,1,p-1)+'           ';
  173.           s1[0]:=#8;
  174.           s:=s1+copy(s,p,255)+'  ';
  175.           s[0]:=#12;
  176.           end;
  177.     write(s);
  178.     write(entry.FileSize:10);
  179.     s:=GetEntryAttributeString(entry.Attributes);
  180.     write(' S',s);
  181.     write(HexStr(entryId,8));
  182.  
  183.     NovTime2String(entry.CreationTime,s);
  184.     delete(s,1,5);dec(s[0],3);
  185.     delete(s,8,2);
  186.     s[3]:='-';s[7]:='-';
  187.     write(' ',s);
  188.  
  189.     GetBinderyObjectName(entry.OwnerId,OwnerName,OwnerType);
  190.     s:=ownerName+'         ';
  191.     s[0]:=#10; write(' ',s);
  192.  
  193.     writeln;
  194.  
  195.     end;
  196. If nwFile.result<>$FF { normal iteration end }
  197.  then writeln('Error using ScanSalvagableFiles.');
  198.  
  199. {$ENDIF}
  200.  
  201. {------------------ show subdir info }
  202.  
  203. SearchFlags:=$3f;
  204. EntryId:=-1;
  205.  
  206. While ScanDirectoryEntry(DH,EntryName,SearchFlags,EntryID,Entry)
  207.  do begin
  208.    s:=entry.EntryName;
  209.     p:=pos('.',s);
  210.     if p=0
  211.      then begin
  212.           s:=s+'               ';
  213.           s[0]:=#11;
  214.           end
  215.      else begin
  216.           delete(s,p,1);
  217.           s:=s+'            ';
  218.           s[0]:=#11;
  219.           end;
  220.     write('\',s);
  221.  
  222.     write(0:10); { filesize }
  223.  
  224.     s:=GetEntryAttributeString(entry.Attributes);
  225.     write(' D',s);
  226.     write(HexStr(entryId,8));
  227.  
  228.     NovTime2String(entry.CreationTime,s);
  229.     delete(s,1,5);dec(s[0],3);
  230.     delete(s,8,2);
  231.     s[3]:='-';s[7]:='-';
  232.     write(' ',s);
  233.  
  234.     GetBinderyObjectName(entry.OwnerId,OwnerName,OwnerType);
  235.     s:=ownerName+'         ';
  236.     s[0]:=#12; write(' ',s);
  237.     writeln;
  238.     end;
  239. if nwFile.result<>$FF { no more matching entries }
  240.  then writeln('Error scanning directory information (err : 4-',nwfile.result,')');
  241.  
  242. DeallocateDirHandle(DH);
  243. end.